<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>class</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C/C++ Keywords</a> &gt; <a href="class.html">class</a>
  </div>

  <div class="name-format">
    class
  </div>

  <div class="syntax-name-format">
    Syntax:
  </div>
  <pre class="syntax-box">
  class class-name : inheritance-list {
  private-members-list;    
  protected:
  protected-members-list;
  public:
  public-members-list;
  } object-list;
</pre>

  <p>The class keyword allows you to create new classes.
  <em>class-name</em> is the name of the class that you wish to create,
  and <em>inheritance-list</em> is an optional list of classes
  inherited by the new class. Members of the class are private by
  default, unless listed under either the protected or public labels.
  <em>object-list</em> can be used to immediately instantiate one or
  more instances of the class, and is also optional. For example:</p>
  <pre class="example-code">
   class Date {
     int Day;
     int Month;
     int Year;
   public:
     void display();
   };           
</pre>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="friend.html">friend</a><br>
    <a href="private.html">private</a><br>
    <a href="protected.html">protected</a><br>
    <a href="public.html">public</a><br>
    <a href="struct.html">struct</a><br>
    <a href="this.html">this</a><br>
    <a href="typename.html">typename</a><br>
    <a href="union.html">union</a><br>
    <a href="virtual.html">virtual</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
